package hello;

import java.util.concurrent.atomic.AtomicLong;

import com.kaki.helloworld.HelloReply;
import com.kaki.helloworld.HelloRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class GreetingController {

    @Autowired
    private HelloWorldClient helloWorldClient;

    @RequestMapping("/greeting")
    public Greeting greeting(@RequestParam(value="name", defaultValue="World") String name) throws InterruptedException {

        HelloRequest req = HelloRequest.newBuilder().setName(name).build();
        HelloReply reply = helloWorldClient.sayHello(req);

        return new Greeting(0, reply.getMessage());
    }
}
